# coding=utf8
from django.core.paginator import Paginator


class DjangoPaginator(object):
    """
    分页
    """

    @classmethod
    def get_paging(cls, data_list, page_size=10, page=1):
        page_object = Paginator(data_list, page_size)
        page_count = page_object.num_pages
        if int(page) >= page_count:
            page = page_count
        page_info = page_object.page(page)
        now_page = page
        if page_info.has_next():
            next_page = page_info.next_page_number()
            now_page = next_page - 1
        else:
            next_page = ""
        if page_info.has_previous():
            before_page = page_info.previous_page_number()
            now_page = before_page + 1
        else:
            before_page = ""
        page_dict = {"page_count": page_count, "next_page": next_page, "before_page": before_page,
                     "now_page": now_page}
        return page_info.object_list, page_dict


if __name__ == '__main__':
    a, b = DjangoPaginator.get_paging([1, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5])
    print(a)
    print(b)
